%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Temporal model.tex
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

In this section we will formalize the model for possibilistic valid-time relational databases. The first subsection is devoted to the formalization of the model. Then, a data manipulation language is defined.

\subsection{\label{subsec:temporal-model}The generalized temporal model}
The model is based on GEFRED~\cite{Medina1994} (Generalized Model of Fuzzy Relational DB) model. This model is extended by adding valid-time support which will be illustrated through the following definitions and examples. The information in the system is defined by the following elements:

\begin{definition}
\label{def:generalized-fuzzy-domain}
\emph{Generalized fuzzy domain.}
Let $D$ be the discourse domain, $\tilde \Pow\left(D \right)$ is the set of all possibility distributions defined on $D$, plus the NULL constant. The generalized fuzzy domain $D_G$ is defined as:
\begin{equation}
\label{eq:generalized-fuzzy-domain}
D_G \subseteq \tilde \Pow\left(D \right)\cup \text{NULL}
\end{equation}
\end{definition}
The datatypes that can be used to represent $D_G$ are shown in table \ref{tbl:gefred-data-types}. 

\begin{definition}
\label{def:typeof-domain}
\textbf{Typeof(a).}
Consider $D_G$ to be a generalized fuzzy domain and the elements in definition \ref{def:valid-time-relation}. Let $a$ be the value for the attribute $A$. The function typeof$\left(a \right)$ returns the datatype associated with the value $a$ and returns a number in $\left[1, 10 \right]$ as shown in Table \ref{tbl:gefred-data-types}.
\begin{equation}
 \label{eq:typeof}
\mbox{Typeof} \left(a \right) \mapsto \left[1, 10 \right]
\end{equation}

\end{definition}


\begin{samepage}
\vglue13pt
%\begin{table}[htbp]
\tcap{\label{tbl:gefred-data-types}Data types}
%\centerline{\small TITLE}
\vglue-6pt
\centerline{\small\baselineskip=13pt
\begin{tabular}{c p{4cm} }\\
No. & Datatype \\ \hline
1 & A single scalar. \\
2 & A single number. \\
3 & A set of mutually exclusive possible scalar assignations. \\
4 & A set of mutually exclusive possible numeric assignations. \\
5 & A possibility distribution in a scalar domain. \\
6 & A possibility distribution in a numeric domain. \\
7 & A real number in $\left[0, 1 \right]$ referring to degree of matching. \\
8 & An \emph{UNKNOWN} value. \\
9 &  An \emph{UNDEFINED} value. \\
10 & A \emph{NULL} value. \\
\hline\\
\end{tabular}
} 
\end{samepage}



It is possible to define a more specific generalized temporal domain, $\T_G$.

\begin{definition}
\label{def:generalized-fuzzy-temporal-domain}
\emph{Generalized fuzzy temporal domain.}
Consider $\T$ to be the temporal domain, and let $\tilde \Pow\left( \T\right)$ be the set of all \emph{normalized} possibility distributions defined on $\T$.
The Generalized Fuzzy Temporal Domain, $\T_G$ is
\begin{equation}
\T_G \subseteq \left \lbrace \tilde \Pow\left( \T\right) \cup \text{NULL} \right \rbrace
\end{equation}
\end{definition}

Note that $\T_G \subseteq D_G$. The datatypes for this domain have been studied previously in section \ref{sec:time-rep} and are shown in tables \ref{tbl:time-point-types} and \ref{tbl:time-interval-types}.

A generalized fuzzy relation is defined in \cite{Medina1994}. Here, we will extend the definition to a generalized fuzzy temporal relation.

\begin{definition}
\emph{Generalized fuzzy temporal relation.}
\label{def:fuzzy-temporal-relation}
Consider the elements in definition \ref{def:valid-time-relation}. Some of them will be extended for the fuzzy case.

\begin{itemize}
%  \item A set of non-temporal fuzzy  or crisp attributes.
% 	\begin{equation}
% 	\label{eq:fuzzy-attribute-set}
% 	A = \left \lbrace A_1, A_2, \ldots, A_n \right \rbrace
% 	\end{equation}
%       The domain for each attribute $A_1, \ldots, A_n$ is $D_1, \ldots, D_n$ respectively. 
% \item The primary key $A_K$ is a subset of $A$.
%       \begin{equation}
%        \label{eq:fuzzy-primary-key-a}
%       A_K \subset A
%       \end{equation}
% A formal definition of primary key for fuzzy relational databases will be given later in Definition \ref{def:generalized-primary-key}.
% \item A set of two attributes; $S$  and $E$ the attributes for the starting and ending ill-known points respectively. $I$ is a possibilistic validity period \emph{PVP} as explained in Section \ref{subsec:ill-known-interval}.
% \begin{equation}
%  \label{eq:fuzzy-attribute-time-interval}
% I = \left \lbrace S, E \right \rbrace
% \end{equation}
\item An attribute called version identifier, $V_{ID}$, will be added to the schema. This attribute is a counter for each different version of the entities. 
% \begin{equation}
%  \label{eq:fuzzy-version-identifier}
% V_{ID} \subset \N
% \end{equation}



\item Then $R_{FTG}$, the schema for the fuzzy valid-time relation is:
\begin{equation}
 \label{eq:fuzzy-valid-time-relation}
R_{FTG} = A \cup V_{ID} \cup  I
\end{equation}
\item The primary key for the fuzzy valid-time relation $R_{FTG}$ is:
\begin{equation}
 \label{eq:fuzzy-valid-time-temporal-pk}
K_{GT} = A_K \cup V_{ID}
\end{equation}
A formal definition of the primary key for fuzzy valid-time relations will be given later in Definition \ref{def:generalized-fuzzy-temporal-key}.


\item We will note by $r$ any valid instance of $R_{FTG}$. 
      \begin{equation}
       \label{eq:fuzzy-valid-time-instance}
      r \subseteq D_1\ x\ \ldots\ x\ D_n x\ \mathbb{N}  x\  \T_G\  x\ \T_G 
      \end{equation}

% \item Let $t$ be a tuple in the instance $r$; $t \in r$:
%       \begin{itemize}
%       \item We will note the values for the starting and the ending  points,$s$ and $e$  respectively. The value for the time interval is given by $i$.
%       \begin{align}
%        \label{eq:fuzzy-starting-point}
%       s = t\left[S \right]\\
%       e = t\left[E \right]\\
%       i = \left(s, e\right)
%       \end{align}
% 
% 
%       \item Let $A_k \subset A$ be the set of the non-temporal attributes that are part of the primary key (equation \eqref{eq:fuzzy-primary-key-a}). Then, $a_k$ denotes the values for the non-temporal attributes of the primary key.
% 	    \begin{equation}
% 	     \label{eq:fuzzy-pk-attribute} 
% 	      a_k = t\left[A_K \right]
% 	    \end{equation}
% 
    \item Let $K_{GT}$ be the primary key for the valid-time relation as given in equation \eqref{eq:fuzzy-valid-time-temporal-pk}. Then, $k$ denotes the values for the attributes in the primary key.
	  \begin{equation}
	   \label{eq:fuzzy-value-pk}
	  k = t\left[K_{GT} \right]
	  \end{equation}
% 
% 
%       \end{itemize}
% \item $Vt$ is the set with all the versions for a given tuple $t$.
% 
% \begin{equation}
%  \label{eq:fuzzy-all-the-versions}
% Vt = r\left(t\left[A_K\right] \right)
% \end{equation}
% If a tuple $t$ contains more than one version, the result of $Vt$ is a set. We will use the index $k$ to address the elements of the set. E.g. $Vt = \left \lbrace t_1, t_2, \ldots, t_n \right \rbrace$. Then $t_k , k \in \left \lbrace 1, \ldots, n \right \rbrace$ is an element of $Vt$.
\end{itemize}
%\end{definition}

Table \ref{tbl:fuzzy-sample-definitions} contains an example instance.


\begin{samepage}
\vglue13pt
%\begin{table}[htbp]
\tcap{\label{tbl:fuzzy-sample-definitions}Sample database containing the instance $r$ of the fuzzy valid-time relation $R_{FTG}$.}
%\centerline{\small DATA TYPES}
\vglue-6pt
\centerline{\small\baselineskip=13pt
\begin{tabular}{c c c c c c c}\\
\hline
& \textbf{A$_1$}  & \textbf{A$_2$}  & $A_3$ & $V_{ID}$ & $S$ & $E$ \\
\hline
$t_1$&$a_{11}$ & $a_{12}$ & $a_{13}$ & $001$ & $s_1$ & $e_1$ \\
$t_2$ & $a_{21}$ & $a_{22}$ & $a_{23}$& $001$ &  $s_2$ & $e_2$ \\
$t_3$ & $a_{11}$ & $a_{12}$ & $a_{31}$& $002$ & $s_3$ & $e_3$\\
\hline\\
\end{tabular}
}
\end{samepage}



% 
% 
% Consider $\A$ to be the set of all the entities, and let $A=\left(A_1, \ldots, A_n \right), A \in \A$ be the set of (fuzzy) attributes that define an entity. Let $\I_{PVP}$ be the set of all the ill-known time intervals and let $I = \left(X, Y \right)$ be a PVP, $I \in \I_{PVP}$.  The pair $\left(A, I\right)$ expresses that the data regarding the entity A are valid during the ill-known time interval I. Let $R_{FTG} \subseteq \A \  x\  \I_{PVP}$ be a valid-time relation. Then, the following equation indicates that the pair $\left(A, I\right)$ is in the relation R:
% 
% \begin{equation}
% \label{eq:fuzzy-rel-def}
% \left( R_{FTG}, \left(A , I\right) \right)
% \end{equation}
% 
 A generalized fuzzy temporal relation $R_{FTG}$ can be noted also by:
\label{def:generalized-fuzzy-temporal-relation}
\begin{equation}
\label{eq:generalized-fuzzy-temporal-relation}
R_{FTG} = \left(\Head, \Body \right)
\end{equation}
Where $\Head$ is the Head of the relation and consists on a fixed set of triplets attribute- domain - compatibility with an optional the valid-time attribute:

\begin{align}
\label{eq:head-valid-time}
\Head = \big \lbrace \left(A_{G1}:D_{G1}\left[,C_{A_{G1}} \right] \right),\\
\nonumber
 \ldots,\\
 \nonumber
  \left(A_{Gn}:D_{Gn}\left[,C_{A_{Gn}} \right] \right),\\
  \nonumber
  \Big[  \left( \text{PVP}, D_{\text{PVP}}\left[,C_{A_{\text{PVP}}} \right] \right) \Big] \big \rbrace
\end{align}
Note that $D_{Gj}$ ($j = 1, \ldots, n$) is the domain for the attribute $A_{Gj}$. $C_{A_{Gj}}$ is the compatibility attribute in the unit interval $\left[0, 1 \right]$.

$\Body$ is the body of the relation and it consists on a set of tuples. Each tuple is a set of triplets attribute- value- degree with an optional valid-time attribute:

\begin{align}
\label{eq:body-valid-time}
\Body = \big \lbrace \ldots \{ \left(A_{G1}:\tilde{d}_{i1}\left[,c_{i1} \right] \right),\\
\nonumber
 \ldots,\\
 \nonumber
  \left(A_{Gn}:\tilde{d}_{in}\left[,c_{in} \right] \right),\\
  \nonumber
   \Big[  \left( \text{PVP}, \tilde{d}_{\text{PVP}} \left[,C_{A_{\text{PVP}}} \right] \right)  \Big] \} \ldots \big \rbrace
\end{align}

\end{definition}


The definition in \cite{Medina1994} for $R_{FTG}$ shows that classical relations are a particular case of this model. 

\begin{example}
\label{ex:sample-ft-database}
 Consider a historical database containing diplomatic documents as explained in example \ref{ex:library-database}. But now, the documents are from the Medieval Ages. Hence, the time is known with imprecision. For simplicity, the ill-known time points are represented as triangular fuzzy numbers. An ill-known time point is given by $[dd/mm/yyyy,a,b]$. The values for $a$ and $b$ are integers. Thus, the date given by $[15/3/1012,5,2]$ is a triangular fuzzy number with the left bound the 10/3/1012, the core on the 15/3/1012 and the right bound on 17/3/1012.
Table \ref{tbl:fuzzy-library-sample} shows the elements Head, $\Head$ and Body, $\Body$. 
\begin{align}
 \label{eq:head-ex}
\Head = & \lbrace \left(\text{ID}:D_{\text{ID}}\right),\\
\nonumber
&  \left(\text{Entity}:D_{\text{Entity}}\right),\\
% \nonumber
% & \left(\text{Loan}:D_{\text{Loan}}\right) \\
\nonumber
& \left(\text{PVP}:D_{\text{PVP}}\right) \rbrace
\end{align}

When the compatibility degree is 1, the component is omitted. The body, $\Body$ consists on all the tuples shown in Table \ref{tbl:fuzzy-library-sample}. 

\end{example}


\begin{samepage}
\vglue13pt
%\begin{table}[htbp]
\tcap{\label{tbl:fuzzy-library-sample}Sample historical database}
%\centerline{\small DATA TYPES}
\vglue-6pt
\centerline{\small\baselineskip=13pt
\begin{tabular}{c c c |p{0.35\columnwidth}}\\
\hline
& & & \centerline{PVP} \\
$\Head$ &  \textbf{ID}  & Entity  &  Start , End \\
\hline
\multirow{3}{*}{$\Body$ } &  3 & E.U. & [15/3/1012, 5, 2] , [30/3/1012, 1, 1] \\
 &4 & N.A.T.O. & [25/3/1012, 3, 2] , [4/4/1012, 1, 7] \\
&5 & C.E.I. & [18/3/1012, 4, 1] , [2/4/1012, 2, 2]\\
% \ 3 & Dracula & [4/4/1012, 3, 3] & UC \\
\hline\\
\end{tabular}
}
\end{samepage}

\begin{definition}
\label{def:value-component}
\emph{Value component.}
The value component $R^{v}_{FTG}$ of a fuzzy temporal relation $R_{FTG}$ is a set with the value components for both the head and the body of the relation:
\begin{align}
\label{eq:value-component}
R^{v}_{FTG} = \left \lbrace \Head^{v},\Body^{v} \right \rbrace \\
\nonumber
\text{Where: } \\
\nonumber
\Head^{v} = \left \lbrace (A_{G1}:D_{G1}), \ldots,  (A_{Gn}:D_{Gn}) \right \rbrace \\
\nonumber
\Body^ {v} = \left \lbrace (A_{G1}:\tilde{d}_{i1}), \ldots,  (A_{Gn}:\tilde{d}_{in})\ \right \rbrace 
\end{align}
\end{definition}

For example, in the case of the document with ID = 3:
\begin{align}
%\label{eq:value-component-s}
\nonumber
\Head^{v} &=  \lbrace \left(\text{ID}:D_{\text{ID}}\right), \left(\text{Entity}:D_{\text{entity}}\right),\\
\nonumber
& \left(\text{PVP}:D_{\text{PVP}}\right) \rbrace \\
\nonumber
\Body^ {v} &= \{\ldots \{ (\text{ID}:3), (\text{Entity}:\text{``E.U.''}) ,\\
\nonumber
& t(\text{PVP}:\left[15/3/1012,5,2\right], \left[30/3/1012,1,1\right]) \} \ldots\}
\end{align}


\begin{definition}
\label{def:compatibility-component}
\emph{Compatibility component.}
The compatibility component $R^{c}_{FTG}$ of a fuzzy temporal relation $R_{FTG}$ is a set with the compatibility components for both the head and the body of the relation:
\begin{align}
\label{eq:compatibility-component}
R^{c}_{FTG} = \left \lbrace \Head^{c},\Body^{c} \right \rbrace \\
\nonumber
\text{Where: } \\
\nonumber
\Head^{c} = \left \lbrace \left[C_{A_{G1}} \right], \ldots,  \left[C_{A_{Gn}} \right] \right \rbrace \\
\nonumber
\Body^ {c} = \left \lbrace \left[ c_{i1} \right], \ldots, \left[ c_{in} \right] \right \rbrace 
\end{align}
\end{definition}

For example, in the case of the document with ID = 3:
\begin{align}
%\label{eq:sample-compatibility-component}
\nonumber
\Head^{c} = & \lbrace \left(C_\text{ID}\right), \left(C_{\text{entity}}\right), \left(C_{\text{PVP}}\right) \rbrace \\
% \nonumber
% &  \\
% \nonumber
% & \left(C_{\text{Loan}}\right) \\
% \nonumber
% & \left(C_{\text{PVP}}\right) \rbrace \\
\nonumber
\Body^ {c} = &\left \lbrace 1, 1, 1, 1 \right \rbrace 
\end{align}


\begin{definition}
\label{def:temporal-component}
\emph{Temporal component.}
The temporal component $R^{t}_{FTG}$ of a fuzzy temporal relation $R_{FTG}$ is a set with the temporal components for both the head and the body of the relation:
\begin{align}
\label{eq:temporal-component}
R^{t}_{FTG} = \left \lbrace \Head^{t},\Body^{t} \right \rbrace \\
\nonumber
\text{Where: } \\
\nonumber
\Head^{t} = \left \lbrace \left( \text{PVP}, D_{\text{PVP}}\left[,C_{A_{\text{PVP}}} \right] \right) \right \rbrace \\
\nonumber
\Body^ {t} = \left \lbrace  \left[ \text{PVP}, \tilde{d}_{\text{PVP}} \left[,C_{A_{\text{PVP}}} \right] \right]  \right \rbrace 
\end{align}
\end{definition}

For example, in the case of the document with ID = 3:
\begin{align}
%\label{eq:sample-temporal-component}
\nonumber
\Head^{t} = & \lbrace \left( \text{PVP}, D_{\text{PVP}}\right)\}\\
\nonumber
\Body^ {t} =& \{ \ldots (\text{PVP}:[\left[15/3/1012,5,2\right],\\
\nonumber
& \left[30/3/1012,1,1\right]]) \ldots\} 
\end{align}


Analogously, it is possible to define both the name value component and the compatibility component for the temporal part.

%the value component for the temporal part and the compatibility component for the temporal part. 

\begin{definition}
\label{def:generalized-primary-key}
\emph{Generalized primary key.}
Consider $D_G$ to be a fuzzy generalized domain, and let $A_{Gs}:D_{Gs}$ be the attributes and the domain of the attribute for each $s \in S \subseteq \left(1, \ldots, n \right)$.
A generalized primary key, $K_G$ is a subset of the head:
\begin{align}
\label{eq:generalized-primary-key}
K_G \subseteq \Head, K_G = \left \lbrace  \left(A_{Gs}:D_{Gs} \right) \right \rbrace \\
\nonumber
s\in S \subseteq \left(1, \ldots, n \right) \\
\end{align}
Subject to the following constraints:
\begin{align}
%\nonumber
\forall s \in S, \text{Typeof } \left(D_{Gs} \right) \in \left \lbrace 1, 2 \right \rbrace \\
\nonumber
\forall i, i' \in \left \lbrace 1, \ldots, m\right \rbrace , \exists s \in S: \\
\nonumber
\left(A_{Gs}:d_{is} \right) \neq \left(A_{Gs}:d_{i's} \right)
\end{align}
\end{definition}

For example, consider the database in Table \ref{tbl:fuzzy-library-sample}. Without any temporal constraint, the primary key $K_G$ is:

\begin{align}
\nonumber
K_G \subseteq \Head, K_G = \left \lbrace  \left(\text{ID}:D_{\text{ID}} \right) \right \rbrace
\end{align}
In this case, the function \emph{Typeof(ID) = 2} (see Definition \ref{def:typeof-domain} and Table \ref{tbl:gefred-data-types}). The primary key for the table is the attribute \emph{ID}, a unique number. Two different documents have two different values for the \emph{ID} attribute.

In order to add valid-time support, the primary key should be re-defined. E.g., consider the historical database. If the primary key is the \emph{ID} attribute, a document should be valid only during one period of time. To resolve this problem, we extend the given primary key with a version identifier. 

%a book could not be loaned more than once. 
%Thus, when a book is loaned, a new entry in the table is added. The \emph{ID} attribute identifies the physical book whereas 



\begin{definition}
\label{def:generalized-fuzzy-temporal-key}
\emph{Generalized fuzzy temporal key.}
Consider $D_G$ to be a fuzzy generalized domain, and let $A_{Gs}:D_{Gs}$ be the attributes and the domain of the attribute for each $s \in S \subseteq \left(1, \ldots, n \right)$. Let  $V$ be a new attribute called \emph{version}. 
A generalized fuzzy temporal key, $K_{GT}$ is a subset of the head.


\begin{align}
\label{eq:generalized-fuzzy-temporal-key}
K_{GT} \subseteq \Head, K_{GT} = \left \lbrace \left(A_{Gs}:D_{Gs} \right)  \right \rbrace \\
\nonumber
\cup  \{\left(V_{ID}:\mathbb{N}  \right)\}\\
\nonumber
s\in S \subseteq \left(1, \ldots, n \right)
\end{align}
Subject to the following constraints:
\begin{align}
\forall s \in S, \text{Typeof } \left(D_{Gs} \right) \in \left \lbrace 1, 2 \right \rbrace \\
\nonumber
\forall i, i' \in \left \lbrace 1, \ldots, m \right \rbrace , \exists s \in S: \\
\nonumber
\left(A_{Gs}:d_{is} \right) \neq \left(A_{Gs}:d_{i's} \right)
\end{align}
\end{definition}

Consider now the database in Table \ref{tbl:fuzzy-library-sample-valid-time}. The primary key is now:

\begin{align}
 \nonumber
K_{GT} \subseteq \Head, K_{GT} = \left \lbrace  \left(\text{ID}:D_{\text{ID}} \right) , \left(V_{\text{ID}}:D_{\text{ID}} \right) \right \rbrace	
%\nonumber
 %\left. \cup  \left(V_{ID}:D_{ID} \right)	\right \rbrace \\
\end{align}

\begin{samepage}
\vglue13pt
%\begin{table}[htbp]
\tcap{\label{tbl:fuzzy-library-sample-valid-time}Sample historical database}
%\centerline{\small DATA TYPES}
\vglue-6pt
\centerline{\small\baselineskip=13pt
\begin{tabular}{c c c c | p{0.35\columnwidth} }\\
\hline
% & & & \multicolumn{2}{c}{PVP} \\
%& & & & \centerline{PVP}\\
{$\Head$}  &  &  & &(Start \\
& \textbf{ID}  & \textbf{V} & Entity& ,End )	\\
 \hline
\multirow{4}{*}{$\Body$}  & 3 & 001 & E.U. & [15/3/1012, 5, 2], [30/3/1012, 1, 1] \\
& 4 & 001 & N.A.T.O. & [25/3/1012, 3, 2] , [4/4/1012, 1, 7]\\
& 5 & 001 & C.E.I. & [18/3/1012, 4, 1] , [2/4/1012, 2, 2]\\
 & 3 & 002 & E.U. & [4/4/1012, 3, 3] , UC \\
\hline\\
\end{tabular}
}
\end{samepage}

\subsection{\label{subsec:data-manipulation}Data manipulation language}

The Generalized Fuzzy Relational Algebra~\cite{Medina1994} manipulates relations like $R_{FTG}$. The operations defined are: \emph{Union, Intersection, Difference, Cartesian Product, Projection, Join} and \emph{Selection}. Thus, in this section we will describe and implement the following operations for temporal databases, as described in \ref{subsubsec:Understanding-valid-time-databases}. The operations implemented are: \emph{Insert, Modify} and \emph{Delete}. The semantics of the operations will be the same that those defined for a crisp temporal database, whereas the temporal representation is made by the possibilistic valid-time period and the ill-known constraints (see sections \ref{sec:prelim} and \ref{sec:time-rep}).
%The algebra for the data manipulation is defined in .

It is important to notice that while the result of the evaluation of any comparison between crisp time intervals is boolean, the evaluation of any comparison between \emph{PVPs} is a value in the unit interval. 

Since the time intervals are now possibilistic valid-time periods, PVPs, the auxiliary functions defined in equations \eqref{eq:close-a-crisp-interval} to \eqref{eq:close-current} are the basis for the following auxiliary functions.

\begin{definition}
\label{def:close-r-a-pvp}
\textbf{CloseR$\left(i_1, i_2\right)$.}
Consider the elements in definition \ref{def:generalized-fuzzy-temporal-relation} and ill-known intervals given by $i_1=(s_1,e_1)$ and $i_2=(s_2,e2)$. The CloseR function closes the PVP given by $i_1$ with a conjunctive combination of ill-known constraints (see section \ref{subsec:interval-evaluation-by-ill-known-constraints}):
\begin{align}
\label{eq:close-r-a-pvp}
\text{CloseR}\left(i_1, i_2\right) &= \\
\begin{cases}
\nonumber
\left(s_1, e_z \right) & \mbox{ if } i_1 = (s_1, UC), \\
& e_z \triangleq \left \lbrace C_1\left(>, s_1 \right), C_2\left(<, s_2 \right) \right \rbrace \\
i_1 & \mbox{ otherwise }
% \nonumber
% I   & \mbox{ if } I \neq \left[X, UC \right] \\
% I = \left[X, Z \right] & \mbox{ if } I = \left[X, UC \right] \\
% & Z \triangleq \left \lbrace C_1\left(>, X \right), C_2\left(<, X' \right) \right \rbrace
\end{cases}
\end{align}
\end{definition}

For example, consider $i_1 = \left[\left[4/4/1012, 3, 3\right] , UC\right]$ and $i_2 = \left[ \left[15/4/1012,2,1\right], UC\right]$. The result for CloseR$\left(i_1, i_2\right)$  is $i_1 = \left[ \left[4/4/1012, 3, 3\right], \left[4,7,13,15 \right] \right]$. The value that closes $i_1$ is a trapezoid in the form $\left[ \alpha, \beta, \gamma, \delta \right]$.

% \begin{definition}
% \label{def:pvp-current-in-relation}
% \textbf{Current$\left(r, a_k \right)$.}
% Consider the elements in definition \ref{def:generalized-fuzzy-temporal-relation}. The function Current $\left(r,a_k \right)$ returns the PVP $i$, if the tuple $t$ with the primary key values given by $a_k$ is currently in the instance $r$ of the relation $R$. The function returns the emtyset otherwise.
% 
% \begin{align}
% \label{eq:pvp-current-in-relation}
% \mbox{Current} \left(r, a_k\right) &=& \\ 
% \begin{cases}
% \nonumber
% t & \mbox{ if } \exists t \in r : i = \left(s, UC \right) \mbox{ and }\\
% &  a_k = t[A_K]\\
% \emptyset & \mbox{ otherwise}
% \end{cases}
% \end{align}
% \end{definition}
% 
% For example, consider the database in Table \ref{tbl:fuzzy-library-sample-valid-time}. The function Current$\left(R_{FTG}, A \right)$ with $A =\left(ID=3\right)$ returns time interval for the current version of $A$, $I = \left[ \left[4/4/1012, 3, 3 \right], UC \right]$. Nevertheless, the time interval for the entity with ID = 4 is the empty set.
% Now it is possible to close the current version of an entity by using \eqref{eq:close-r-a-pvp} and \eqref{eq:pvp-current-in-relation}.

\begin{definition}
\label{def:pvp-close-current-version}
\textbf{Close-current$\left(r, t \right)$.}
Consider the elements in definition \ref{def:generalized-fuzzy-temporal-relation}. The function Close-current$\left(r, t \right)$ closes any current version $t_k$ of the entity given by $t$ if it exists and add the new version $t$. In order to implement the functionality, the variables in equation \eqref{eq:variables-current-version} are used and the function Current as given by equation \eqref{eq:current-in-relation}.

\begin{eqnarray}
\label{eq:pvp-close-current}
\text{Close-current} \left(r, t \right) =\\
\begin{cases}
\nonumber
r - t_{CUR} \cup \lbrace t_{UP}\rbrace \cup \lbrace t \rbrace
& \mbox{ if } \mbox{Current } \left(r, t[A_K] \right) \neq \emptyset \\
% R - \left(A, I \right) \cup \left \lbrace \left(A, \mbox{ CloseR } \left(I, J\right) \right)\right \rbrace \cup \left \lbrace\left(A, J\right) \right \rbrace  \\
% \nonumber
% \mbox{ if  Current } \left(R, A \right) \neq \emptyset\\ %\wedge J > \mbox{ CloseR } \left(I, J \right)   \\
\nonumber r , \text{ otherwise}
\end{cases}
\end{eqnarray}
\end{definition}





% Then, the function close - current$\left(R_{FTG}, A, J \right)$ closes any current version of the entity $A$ if it exists and add the new version $\left(A, J \right)$.

% \begin{eqnarray}
% \label{eq:pvp-close-current}
% \text{Close-current} \left(R_{FTG}, \left(A, J \right) \right) =\\
% \begin{cases}
% \nonumber
% \big \lbrace R_{FTG} - \left(A, I \right) \cup \left \lbrace \left(A, \mbox{ CloseR } \left(I, J\right) \right) \right \rbrace \cup \left \lbrace \left(A, J\right)\right \rbrace  \big \rbrace \\
% \nonumber
% \mbox{ if Current } \left(R_{FTG}, A \right) \neq \emptyset \\ %\wedge J > \mbox{ CloseR } \left(I, J \right)   \\
% \nonumber R , \text{ in any other case}
% \end{cases}
% \end{eqnarray}
% \end{definition}

For example, consider the database in Table  \ref{tbl:fuzzy-library-sample-valid-time}. The function Close-current1$\left(R_{FTG}, \left(ID=3\right) \right.,$ $\left. \left[ \left[15/4/1012,2,1\right], UC\right]\right)$ closes the current version of for the patient with ID=3 and creates a new version with the specified time interval.

\subsubsection{\label{subsubsec:modify-fuzzy-temporal}Modify}
This operation adds new information about an existing entity (given by the tuple $t$) in the instance $r$ of the fuzzy temporal relation $R_{FTG}$. The modify operation does not remove any previous value of the entity.
Note that the modify operation is only applicable when the entity is current in the relation; $ t \in r,  = \left(s, \UC \right)$.

\begin{definition}
\emph{$\MOD \left( r, t \right)$}. 
Consider the elements in definition \ref{def:generalized-fuzzy-temporal-relation}. The algorithm for the modify operation is defined as follows.
\end{definition}


\begin{align}
\label{eq:modify-fuzzy-temporal}
\MOD \left( r, t\right) =\\
%\begin{cases}
\nonumber
\mbox{ Close-current }\left(r, t \right) 
% \mbox{ if Current}\left(R ,A \right) \neq \emptyset \\
% R,  \mbox{ otherwise }
%\end{cases}
\end{align}

\subsubsection{\label{subsubsec:insert-fuzzy-temporal}Insert}
The user wants to store an entity (given by the tuple $t$) which is valid in the instance $r$ of the fuzzy temporal relation $R_{FTG}$ during the time interval specified by the PVP, $i = \left(s, e \right)$.
%
%
%The interpretation of the insert operation is the following: The user wants to store in the database that an object $A$  is true for some period(s) of time $I$ in the given relation $R$. To indicate that the object $A$ is current in the relation, the special value Until Current, $\UC$  is used. 
There are the following cases when performing an insert operation:
\begin{enumerate}
\item The entity was never in the relation: The entity is added with the valid-time indicated by the PVP, $i$.
For example, consider the database given by Table \ref{tbl:fuzzy-library-sample-valid-time}. The following sentences correspond with the insertion of the first validity period for each document.

\begin{verbatim}
Insert(3,'E.U.',
[[15/3/1012, 5, 2],
        [30/3/1012, 1, 1]]);
Insert(4,'N.A.T.O.',
[[25/3/1012, 3, 2], 
        [4/4/1012, 1, 7]]);
Insert(5,'C.E.I.',
[[18/3/1012, 4, 1], 
        [2/4/1012, 2, 2]]);
\end{verbatim}





\item The entity is in the relation. Depending on the value of the time interval $i$, there are three possibilities:
	\begin{enumerate}
	\item Insert $t$ in the instance $r$ of the relation $R_{FTG}$. If the time interval $i$ does not overlap any other valid-time interval in the relation $R_{FTG}$. Note that here, the result of the overlaps operator is in the unit interval.
For example, the document with ID=3 is still valid. The insert sentence is the following.

 \begin{verbatim}
Insert(3,'E.U.',
[[4/4/1012, 3, 3], UC]);
	      \end{verbatim}

	\item Modify and close the current version of the entity and insert a new version. For example, consider now that the document with ID=3 was valid  around the 24/4/1012 (this is model by a triangular fuzzy number: $\left[24/4/1012, 1, 1 \right]$). Here the problem is that the document with ID=3 was valid around 4/4/1012, but, for some reason, the ending date was not stored. If the document is again valid, then it is necessary to set the ending date and add a new row with the new starting date. %This is illustrated in Table \ref{tbl:library-sample-2}, the insert sentence is:
	    \begin{verbatim}
Insert(3,'E.U.',
[[24/4/1012, 1, 1], UC]]);
	      \end{verbatim}

	\item Reject the insertion, if the time interval $i$ does overlap with a degree of 1 any existing valid-time interval for the entity in the relation. For example, consider now that the document manager wants to introduce a past validity period for the document with ID=3. The validity starting date for the document was around 6/4/12/1012 and the ending date was around 25/4/1012. As this interval does overlaps other time intervals with a degree of 1, it is not possible that the document was valid during two different periods of time. Therefore, the insertion is rejected. The insert sentence is:

	      \begin{verbatim}
Insert(3,'E.U.',
[[6/4/12/1012, 1, 1],
         [25/4/1012, 1, 1]]);
	    \end{verbatim}
	\end{enumerate}

\end{enumerate}

\begin{definition}
 \emph{$\INS \left(r, t \right)$}.
Consider the elements in definition \ref{def:generalized-fuzzy-temporal-relation}. The algorithm for the implementation of the insert operation is defined as follows.
\end{definition}



\begin{align}
\label{eq:insert-fuzzy-temporal}
\INS \left(r, t\right) =\\
\begin{cases}
\nonumber
r & \mbox{ if }  \exists t_k \in V(t), \\
\nonumber &\left(t[S,E] \mbox{ overlaps } t_k[S,E]=1\right)\\
\nonumber
r \cup \lbrace t \rbrace
& \mbox{ if }  V(t)=\emptyset \mbox{ or }\\
\nonumber & \forall t_k \in V(t), \\
\nonumber & \left(t[S,E] \mbox{ overlaps } t_k[S,E]\right) < 1\\
% 
% R \cup \left(A, I \right) & \mbox{ if }  (A, I ) \not \in R  \mbox{ or } \\
%  &   \left(A, J\right) \in R \mbox{ and } \lnot \left(I \mbox{ Overlaps } J\right) \\
\mbox{modify(r, t)} & \mbox{ otherwise }    %\mbox{ if } \exists J \left(A,J\right) \in R \wedge \mbox{Current(A,J)} \\ 
%R, &   
\end{cases} 	
\end{align}




\subsubsection{\label{subsubsec:delete-fuzzy-temporal}Delete}
The delete operation logically removes an entity which is valid in the instance $r$ of the relation $R_{FTG}$.

\begin{definition}
 \emph{$\DEL \left(r, t \right) $}.
Consider the elements in definition \ref{def:generalized-fuzzy-temporal-relation}. The algorithm for the delete operation is defined as follows.
\end{definition}


\begin{align}
\label{eq:delete-fuzzy-temporal}
\DEL \left(r, t\right) =
\nonumber
r - V(t)
\end{align}

For example, consider that the document manager wants to delete the history for the document with ID = 3. The following sentence deletes all the rows for the documents with ID = 3.

\begin{verbatim}
 Delete(3,'E.U.');
\end{verbatim}


% \subsubsection{\label{subsubsec:revise-fuzzy-temporal}Revise}
% This operation replaces the old values for the entity $A'= \left(a_1', \ldots, a_n' \right) $ with the new values specified by $A = \left(a_1, \ldots, a_n \right)$ in the relation $R$, at a given time interval $I$. This operation is used when a correction on the values for the entity $A$ should be done.
% \begin{align}
% \label{eq:revise-fuzzy-temporal}
% \REV\left(R, \left(A, I \right)\right)=\\
% \begin{cases}
% \nonumber
%  R - \left(A', I \right) \cup \left \lbrace\left(A, I \right)\right \rbrace  & \mbox{ if } \left(A', I \right) \in R \\%: A = \left(a_1, \ldots, a_n \right),\\
% %A'= \left(a_1', \ldots, a_n' \right)   \\   
% R, & \mbox{ otherwise }
% \end{cases}
% \end{align} 
% 
% 
% For example, consider now that the librarian wants to make a correction in the title for the book with ID = 5. The new title is `Harry Potter IV'. The revise sentence is:
% 
% \begin{verbatim}
% Revise(5,'Harry Potter IV', 
% [[18/3/1012, 4, 1], 
%           [2/4/1012, 2, 2]]);
% \end{verbatim}
